package view;

import javafx.application.Application;
import javafx.beans.property.*;
import javafx.beans.value.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import model.Paper;
import model.Review;


/** 
 * This class displays a survey using a wizard 
 * @author Cody Thompson
 */

public class AddReview extends Application {
	
	private MainPanel mainP;
	
	private Paper paperRev;
	
	public AddReview(MainPanel mp, Paper pap) {
		mainP = mp;
		paperRev = pap;
	}
	@Override
	public void start(Stage stage) {
		stage.setScene(new Scene(new ReviewWizard(stage, mainP, paperRev), 600, 400));
		stage.show();
	}
	
}

/** This class shows a satisfaction survey */
class ReviewWizard extends Wizard {
	private MainPanel mainP;
	private Paper paperRev;
	Stage owner;
	public ReviewWizard(Stage owner, MainPanel mp, Paper pap) {
		super(new PageOne(), new PageTwo(), new PageThree(), new PageFour(), new PageFive(), new PageSix(), new PageSeven(),
				new PageEight(), new PageNine(), new PageTen(), new PageEleven());
		this.owner = owner;
		mainP = mp;
		paperRev = pap;
		//System.out.print(mainP.getMF().getUser().getName());
	}
	@Override
	public void finish() {	
		int[] rats = { 
				(int) UploadRev.instance.question1.get(), (int) UploadRev.instance.question2.get(), 
				(int) UploadRev.instance.question3.get(), (int) UploadRev.instance.question4.get(), 
				(int) UploadRev.instance.question5.get(), (int) UploadRev.instance.question6.get(), 
				(int) UploadRev.instance.question7.get(), (int) UploadRev.instance.question8.get(), 
				(int) UploadRev.instance.question9.get(), (int) UploadRev.instance.question10.get(), 
				};
		String[] stats = {
				UploadRev.instance.key1.get(), UploadRev.instance.key2.get(), UploadRev.instance.key3.get(), 
				UploadRev.instance.key4.get(), UploadRev.instance.key5.get(), UploadRev.instance.key6.get(), 
				UploadRev.instance.key7.get(), UploadRev.instance.key8.get(), UploadRev.instance.key9.get(), 
				UploadRev.instance.key10.get(), 
		};
		
		//Review rev = new Review(rats, stats, mainP.getMF().getUser()));
		paperRev.addReview(new Review(rats, stats, mainP.getMF().getUser()));
		
		/*Paper pap = new Paper(UploadRev.instance.paper.getAbsoluteFile(), UploadRev.instance.title.get(), 
				"e", UploadRev.instance.key1.get(), UploadRev.instance.abstrac.get());*/
		//mainP.addPap(pap);
		owner.close();
	}
	@Override
	public void cancel() {
		System.out.println("Cancelled");
		owner.close();
	}
}

/** Simple placeholder class for the customer entered survey response. */
class UploadRev {
	DoubleProperty question1 = new SimpleDoubleProperty();
	DoubleProperty question2 = new SimpleDoubleProperty();
	DoubleProperty question3 = new SimpleDoubleProperty();
	DoubleProperty question4 = new SimpleDoubleProperty();
	DoubleProperty question5 = new SimpleDoubleProperty();
	DoubleProperty question6 = new SimpleDoubleProperty();
	DoubleProperty question7 = new SimpleDoubleProperty();
	DoubleProperty question8 = new SimpleDoubleProperty();
	DoubleProperty question9 = new SimpleDoubleProperty();
	DoubleProperty question10 = new SimpleDoubleProperty();
	StringProperty key1 = new SimpleStringProperty();
	StringProperty key2 = new SimpleStringProperty();
	StringProperty key3 = new SimpleStringProperty();
	StringProperty key4 = new SimpleStringProperty();
	StringProperty key5 = new SimpleStringProperty();
	StringProperty key6 = new SimpleStringProperty();
	StringProperty key7 = new SimpleStringProperty();
	StringProperty key8 = new SimpleStringProperty();
	StringProperty key9 = new SimpleStringProperty();
	StringProperty key10 = new SimpleStringProperty();

	static UploadRev instance = new UploadRev();
}

class PageOne extends WizardPage {
	
	public PageOne() {
		super("Instructions");
	}
	
	@Override
	Parent getContent() {
		nextButton.setDisable(false);
		finishButton.setDisable(true);
		Label lab = new Label("Please provide a numeric rating on a 5-point scale for each question, "
				+ "along with a brief rationale for each numeric rating. In doing so, please discuss both "
				+ "the strengths and the weaknesses of each paper so that the editors and authors can "
				+ "understand your reasoning. Please phrase your reviews politely; even 'bad' papers "
				+ "represent a lot of work on the part of the authors. The review may be the basis for further "
				+ "revisions of the paper or the work that the paper reports. We all know how hurtful a "
				+ "needlessly negative review can be, and how helpful a positive one can be; please try to "
				+ "bear that in mind when you are writing yours.");
		lab.wrapTextProperty().set(true);
		return VBoxBuilder.create().spacing(5).children(lab).build();
	}
}

/** This page gathers the title of the paper */
class PageTwo extends WizardPage {
	
	private Slider slide;
	public PageTwo() {
		super("Question 1");
		nextButton.setDisable(true);
		finishButton.setDisable(true);
	}


	@Override
	Parent getContent() {
		slide = new Slider();
		slide.setMin(1);
		slide.setMax(5);
		slide.setValue(3);
		slide.setShowTickLabels(true);
		slide.setShowTickMarks(true);
		slide.setMajorTickUnit(1);
		slide.setMinorTickCount(0);
		slide.snapToTicksProperty().set(true);

		TextArea textArea = TextAreaBuilder.create().wrapText(true).promptText("").build();
		textArea.textProperty().addListener(new ChangeListener<String>() {
			@Override public void changed(ObservableValue<? extends String> observableValue, String oldValue, String newValue) {
				nextButton.setDisable(newValue.isEmpty());
			}
		});
		UploadRev.instance.question1.bind(slide.valueProperty());
		UploadRev.instance.key1.bind(textArea.textProperty());
		Label bab = LabelBuilder.create().wrapText(true).text("Can the content be directly applied by classroom "
				+ "instructors or curriculum designers?").build();
		return VBoxBuilder.create().spacing(15).children(bab, slide, textArea).build();
	}	
}

class PageThree extends WizardPage {
	private Slider slide;

	public PageThree() {
		super("Question 2");

		nextButton.setDisable(true);
		finishButton.setDisable(true);
	}

	@Override
	Parent getContent() {
		slide = new Slider();
		slide.setMin(1);
		slide.setMax(5);
		slide.setValue(3);
		slide.setShowTickLabels(true);
		slide.setShowTickMarks(true);
		slide.setMajorTickUnit(1);
		slide.setMinorTickCount(0);
		slide.snapToTicksProperty().set(true);

		TextArea textArea = TextAreaBuilder.create().wrapText(true).promptText("").build();
		textArea.textProperty().addListener(new ChangeListener<String>() {
			@Override public void changed(ObservableValue<? extends String> observableValue, String oldValue, String newValue) {
				nextButton.setDisable(newValue.isEmpty());
			}
		});
		UploadRev.instance.question2.bind(slide.valueProperty());
		UploadRev.instance.key2.bind(textArea.textProperty());
		Label bab = LabelBuilder.create().wrapText(true).text("Does the work appeal to a broad readership "
				+ "interested in engineering education or is it narrowly specialized?").build();
		return VBoxBuilder.create().spacing(15).children(bab, slide, textArea).build();
	}
}

class PageFour extends WizardPage {
	private Slider slide;

	public PageFour() {
		super("Question 3");

		nextButton.setDisable(true);
		finishButton.setDisable(true);
	}

	@Override
	Parent getContent() {
		slide = new Slider();
		slide.setMin(1);
		slide.setMax(5);
		slide.setValue(3);
		slide.setShowTickLabels(true);
		slide.setShowTickMarks(true);
		slide.setMajorTickUnit(1);
		slide.setMinorTickCount(0);
		slide.snapToTicksProperty().set(true);

		TextArea textArea = TextAreaBuilder.create().wrapText(true).promptText("").build();
		textArea.textProperty().addListener(new ChangeListener<String>() {
			@Override public void changed(ObservableValue<? extends String> observableValue, String oldValue, String newValue) {
				nextButton.setDisable(newValue.isEmpty());
			}
		});
		UploadRev.instance.question3.bind(slide.valueProperty());
		UploadRev.instance.key3.bind(textArea.textProperty());
		Label bab = LabelBuilder.create().wrapText(true).text("Does the work address a significant problem? ").build();
		return VBoxBuilder.create().spacing(15).children(bab, slide, textArea).build();
	}
}
class PageFive extends WizardPage {
	private Slider slide;

	public PageFive() {
		super("Question 4");

		nextButton.setDisable(true);
		finishButton.setDisable(true);
	}

	@Override
	Parent getContent() {
		slide = new Slider();
		slide.setMin(1);
		slide.setMax(5);
		slide.setValue(3);
		slide.setShowTickLabels(true);
		slide.setShowTickMarks(true);
		slide.setMajorTickUnit(1);
		slide.setMinorTickCount(0);
		slide.snapToTicksProperty().set(true);

		TextArea textArea = TextAreaBuilder.create().wrapText(true).promptText("").build();
		textArea.textProperty().addListener(new ChangeListener<String>() {
			@Override public void changed(ObservableValue<? extends String> observableValue, String oldValue, String newValue) {
				nextButton.setDisable(newValue.isEmpty());
			}
		});
		UploadRev.instance.question4.bind(slide.valueProperty());
		UploadRev.instance.key4.bind(textArea.textProperty());
		Label bab = LabelBuilder.create().wrapText(true).text("Does the author build upon relevant references and bodies of knowledge ").build();
		return VBoxBuilder.create().spacing(15).children(bab, slide, textArea).build();
	}
}
class PageSix extends WizardPage {
	private Slider slide;

	public PageSix() {
		super("Question 5");

		nextButton.setDisable(true);
		finishButton.setDisable(true);
	}

	@Override
	Parent getContent() {
		slide = new Slider();
		slide.setMin(1);
		slide.setMax(5);
		slide.setValue(3);
		slide.setShowTickLabels(true);
		slide.setShowTickMarks(true);
		slide.setMajorTickUnit(1);
		slide.setMinorTickCount(0);
		slide.snapToTicksProperty().set(true);

		TextArea textArea = TextAreaBuilder.create().wrapText(true).promptText("").build();
		textArea.textProperty().addListener(new ChangeListener<String>() {
			@Override public void changed(ObservableValue<? extends String> observableValue, String oldValue, String newValue) {
				nextButton.setDisable(newValue.isEmpty());
			}
		});
		UploadRev.instance.question5.bind(slide.valueProperty());
		UploadRev.instance.key5.bind(textArea.textProperty());
		Label bab = LabelBuilder.create().wrapText(true).text("If a teaching intervention is reported, is it adequately "
				+ "evaluated in terms of its impact on learning in actual use? ").build();
		return VBoxBuilder.create().spacing(15).children(bab, slide, textArea).build();
	}
}
class PageSeven extends WizardPage {
	private Slider slide;

	public PageSeven() {
		super("Question 6");

		nextButton.setDisable(true);
		finishButton.setDisable(true);
	}

	@Override
	Parent getContent() {
		slide = new Slider();
		slide.setMin(1);
		slide.setMax(5);
		slide.setValue(3);
		slide.setShowTickLabels(true);
		slide.setShowTickMarks(true);
		slide.setMajorTickUnit(1);
		slide.setMinorTickCount(0);
		slide.snapToTicksProperty().set(true);

		TextArea textArea = TextAreaBuilder.create().wrapText(true).promptText("").build();
		textArea.textProperty().addListener(new ChangeListener<String>() {
			@Override public void changed(ObservableValue<? extends String> observableValue, String oldValue, String newValue) {
				nextButton.setDisable(newValue.isEmpty());
			}
		});
		UploadRev.instance.question6.bind(slide.valueProperty());
		UploadRev.instance.key6.bind(textArea.textProperty());
		Label bab = LabelBuilder.create().wrapText(true).text("Does the author use methods appropriate to the goals, both for the instructional "
				+ "intervention and the evaluation of impact on learning? ").build();
		return VBoxBuilder.create().spacing(15).children(bab, slide, textArea).build();
	}
}
class PageEight extends WizardPage {
	private Slider slide;

	public PageEight() {
		super("Question 7");

		nextButton.setDisable(true);
		finishButton.setDisable(true);
	}

	@Override
	Parent getContent() {
		slide = new Slider();
		slide.setMin(1);
		slide.setMax(5);
		slide.setValue(3);
		slide.setShowTickLabels(true);
		slide.setShowTickMarks(true);
		slide.setMajorTickUnit(1);
		slide.setMinorTickCount(0);
		slide.snapToTicksProperty().set(true);

		TextArea textArea = TextAreaBuilder.create().wrapText(true).promptText("").build();
		textArea.textProperty().addListener(new ChangeListener<String>() {
			@Override public void changed(ObservableValue<? extends String> observableValue, String oldValue, String newValue) {
				nextButton.setDisable(newValue.isEmpty());
			}
		});
		UploadRev.instance.question7.bind(slide.valueProperty());
		UploadRev.instance.key7.bind(textArea.textProperty());
		Label bab = LabelBuilder.create().wrapText(true).text("Did the author provide sufficient detail to replicate and evaluate?").build();
		return VBoxBuilder.create().spacing(15).children(bab, slide, textArea).build();
	}
}
class PageNine extends WizardPage {
	private Slider slide;

	public PageNine() {
		super("Question 8");

		nextButton.setDisable(true);
		finishButton.setDisable(true);
	}

	@Override
	Parent getContent() {
		slide = new Slider();
		slide.setMin(1);
		slide.setMax(5);
		slide.setValue(3);
		slide.setShowTickLabels(true);
		slide.setShowTickMarks(true);
		slide.setMajorTickUnit(1);
		slide.setMinorTickCount(0);
		slide.snapToTicksProperty().set(true);

		TextArea textArea = TextAreaBuilder.create().wrapText(true).promptText("").build();
		textArea.textProperty().addListener(new ChangeListener<String>() {
			@Override public void changed(ObservableValue<? extends String> observableValue, String oldValue, String newValue) {
				nextButton.setDisable(newValue.isEmpty());
			}
		});
		UploadRev.instance.question8.bind(slide.valueProperty());
		UploadRev.instance.key8.bind(textArea.textProperty());
		Label bab = LabelBuilder.create().wrapText(true).text("Is the paper clearly and carefully written?").build();
		return VBoxBuilder.create().spacing(15).children(bab, slide, textArea).build();
	}
}
class PageTen extends WizardPage {
	private Slider slide;

	public PageTen() {
		super("Question 9");

		nextButton.setDisable(true);
		finishButton.setDisable(true);
	}

	@Override
	Parent getContent() {
		slide = new Slider();
		slide.setMin(1);
		slide.setMax(5);
		slide.setValue(3);
		slide.setShowTickLabels(true);
		slide.setShowTickMarks(true);
		slide.setMajorTickUnit(1);
		slide.setMinorTickCount(0);
		slide.snapToTicksProperty().set(true);

		TextArea textArea = TextAreaBuilder.create().wrapText(true).promptText("").build();
		textArea.textProperty().addListener(new ChangeListener<String>() {
			@Override public void changed(ObservableValue<? extends String> observableValue, String oldValue, String newValue) {
				nextButton.setDisable(newValue.isEmpty());
			}
		});
		UploadRev.instance.question9.bind(slide.valueProperty());
		UploadRev.instance.key9.bind(textArea.textProperty());
		Label bab = LabelBuilder.create().wrapText(true).text("Does the paper adhere to accepted "
				+ "standards of style, usage, and composition?").build();
		return VBoxBuilder.create().spacing(15).children(bab, slide, textArea).build();
	}
}
class PageEleven extends WizardPage {
	private Slider slide;

	public PageEleven() {
		super("Question 10");

		nextButton.setDisable(true);
		finishButton.setDisable(true);
	}

	@Override
	Parent getContent() {
		slide = new Slider();
		slide.setMin(1);
		slide.setMax(5);
		slide.setValue(3);
		slide.setShowTickLabels(true);
		slide.setShowTickMarks(true);
		slide.setMajorTickUnit(1);
		slide.setMinorTickCount(0);
		slide.snapToTicksProperty().set(true);

		TextArea textArea = TextAreaBuilder.create().wrapText(true).promptText("").build();
		textArea.textProperty().addListener(new ChangeListener<String>() {
			@Override public void changed(ObservableValue<? extends String> observableValue, String oldValue, String newValue) {
				finishButton.setDisable(newValue.isEmpty());
			}
		});
		UploadRev.instance.key10.bind(textArea.textProperty());
		UploadRev.instance.question10.bind(slide.valueProperty());
		Label bab = LabelBuilder.create().wrapText(true).text("Summary rating and comments").build();
		return VBoxBuilder.create().spacing(15).children(bab, slide, textArea).build();
	}
}